<html>
<meta http-equiv="content" content="text/html" charset="utf-8">
<head>
<style>
body {background-color:#0C2A4C}
h1 {
    color:lightgray;
    font-family:verdana;
    font-size:200%;
}
h2 {
    color:lightgray;
    font-family:verdana;
    font-size:150%;
}
p  {
    color:lightgray;
    font-family:arial;
    font-size:130%;
}
</style>
</head>
<body>
<?php include "menu.inc"; ?>
<div class="header" align="right">
    	<div class="logo">
       	<a href="index.html"><img src="logoShalom.jpg" alt="Igreja Batista Shalom" /></a>
        </div>
</div>

<?php
$operacao = $_POST["operacao"];
include "conecta_pg.inc";
if ($operacao=="incluir")
{
	$nome_curso = $_POST["nome_curso"];
	$descricao_curso = $_POST["descricao_curso"];
	$codigo_curriculo = $_POST["codigo_curriculo"];
	$sql = "INSERT INTO curso (nome_curso,descricao_curso,codigo_curriculo) VALUES";
	$sql .= "('$nome_curso','$descricao_curso','$codigo_curriculo')";
	$resultado = pg_query ($sql);
	echo "
			<html>
			<meta http-equiv=\"content\" content=\"text/html\" charset=\"utf-8\">
			<title>Inscricoes_UDF - Cursos</title>
			<body>
			<div align=\"center\"><center>
			<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"45%\" bordercolor=\"#0C2A6F\" height=\"19\">
			<tr>
			<td width=\"6%\" bgcolor=\"#000080\" height=\"19\"><h1 align=\"center\">
			Cadastro de Curso</h1></font></td>
			</tr><tr>
			<td width=\"100%\" align=\"center\" valign=\"center\" height=\"19\"><p>Curso incluído com sucesso!</p></td>
			</tr></table>

			<form action=\"cursos_form.php\" method=\"POST\">
			<br><input type=\"submit\" name=\"voltar\" value=\"<< Voltar\">
			</form>
			</center></div></body></html>";
}
elseif ($operacao=="excluir")
{
	$codigo_curso = $_POST["codigo_curso"];
	$sql = "DELETE FROM curso WHERE codigo_curso=$codigo_curso";
	$resultado = pg_query($sql);
	$linhas = pg_affected_rows($resultado);
	if ($linhas==1)
	{ echo "
		<html>
		<meta http-equiv=\"content\" content=\"text/html\" charset=\"utf-8\">
		<title>Inscricoes_UDF - Cursos</title>
		<body>
		<div align=\"center\"><center>
		<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"45%\" bordercolor=\"#0C2A6F\" height=\"19\">
		<tr>
		<td width=\"6%\" bgcolor=\"#000080\" height=\"19\"><h1 align=\"center\">
		Cadastro de Curso</h1></font></td>
		</tr><tr>
		<td width=\"100%\" align=\"center\" valign=\"center\" height=\"19\"><p>Curso excluído com sucesso!</p></td>
		</tr></table>
		<form action=\"cursos_dorm.php\" method=\"POST\">
		<br><input type=\"submit\" name=\"voltar\" value=\"<< Voltar\">
		</form>
		</center></div></body></html>";
	 }
	else { echo "

		<html>
		<meta http-equiv=\"content\" content=\"text/html\" charset=\"utf-8\">
		<title>Inscricoes_UDF - Cursos</title>
		<body>
		<div align=\"center\"><center>
		<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"45%\" bordercolor=\"#0C2A6F\" height=\"19\">
		<tr>
		<td width=\"6%\" bgcolor=\"#000080\" height=\"19\"><h1 align=\"center\">
		Cadastro de Curso</h1></font></td>
		</tr><tr>
		<td width=\"100%\" align=\"center\" valign=\"center\" height=\"19\"><p>Curso não encontrado!<p></td>
		</tr></table>
		<form action=\"cursos_form.php\" method=\"POST\">
		<br><input type=\"submit\" name=\"voltar\" value=\"<< Voltar\">
		</form>
		</center></div></body></html>";
	}
}
elseif ($operacao=="mostrar")
{
$resultado = pg_query ("SELECT codigo_curso, nome_curso, nome_curriculo, descricao_curso FROM curso, curriculo WHERE curso.codigo_curriculo=curriculo.codigo_curriculo");
	$linhas = pg_num_rows ($resultado);
	echo "<h1 align=\"center\">Lista de cursos UDF cadastrados</h1>";
	echo "
		<html>
		<meta http-equiv=\"content\" content=\"text/html\" charset=\"utf-8\">
		<title>Inscrições UDF - Cursos</title>
		<body>
		<div align=\"center\"> <center>
		<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"85%\" bordercolor=\"#0C2A6F\" height=\"19\" >
		<tr>
		<td width=\"8%\" bgcolor=\"#0C2A6F\" height=\"19\"><h2 align=\"center\">
		Código</h2></font></td>
		<td width=\"20%\" bgcolor=\"#0C2A6F\" height=\"19\"><h2 align=\"center\">
		Curso</h2></font></td>
		<td width=\"15%\" bgcolor=\"#0C2A6F\" height=\"19\"><h2 align=\"center\">
		Currículo</h2></font></td>
		<td width=\"57%\" bgcolor=\"#0C2A6F\" height=\"19\"><h2 align=\"center\">
		Descrição</h2></font></td>
		</tr></table></center></div></body></html>";
	for ($i=0; $i<$linhas; $i++)
	{
		$reg = pg_fetch_row($resultado);
		echo "
			<html>
			<meta http-equiv=\"content\" content=\"text/html\" charset=\"utf-8\">
			<body>
			<div align=\"center\"><center>
			<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"85%\" bordercolor=\"#0C2A6F\" height=\"19\">
			<tr>
			<td width=\"8%\" align=\"center\" valign=\"center\" height=\"19\"><p>$reg[0]</p></td>
			<td width=\"20%\" height=\"19\" align=\"left\" valign=\"center\"><p>$reg[1]</p></td>
			<td width=\"15%\" height=\"19\" align=\"left\" valign=\"center\"><p>$reg[2]</p></td>
			<td width=\"57%\" height=\"19\" align=\"left\" valign=\"center\"><p>$reg[3]</p></td>
			</tr></table></center></div></body></html>";
	}
	echo "
		<html>
		<meta http-equiv=\"content\" content=\"text/html\" charset=\"utf-8\">
		<body>
		<div align=\"center\"><center>

		<form action=\"cursos_form.php\" method=\"POST\">
		<br><input type=\"submit\" name=\"voltar\" value=\"<< Voltar\">
		</form>
		<center></div></body></html>";

}
pg_close($conexao);
?>
</body>
</html>
